/**
 * 
 */
package cn.xo68.ide.plugin.common.resources;

import cn.xo68.core.bundle.XmlControl;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * 从bundle资源中读取 message信息
 * @author nnsword
 * @date 2017-12-10 22:39:44
 *
 */
public final class Messages {
    @NotNull
    public static final String BUNDLE_MESSAGE="messages";
    @NotNull
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_MESSAGE, Locale.getDefault(), new XmlControl());

    public static final String DIALOG_CLOSE_TEXT = Messages.message("wts.common.close");

    public static final String DIALOG_ABOUT_TITLE = Messages.message("wts.dialog.about.title");

    public static final String DIALOG_ABOUT_BTN_SITE_TEXT = Messages.message("wts.dialog.about.opensite");

    public static final String DIALOG_ABOUT_BTN_SITE_URI= Messages.message("wts.dialog.about.site");

    public static final String DIALOG_ABOUT_BTN_CLOSE_TEXT = Messages.message("wts.dialog.about.close");

    public static final String DIALOG_ABOUT_REMARK = Messages.message("wts.dialog.about.remark");

    public static final String DIALOG_CREATE_PROJECT_TITLE = Messages.message("wts.dialog.createproject.title");
    public static final String DIALOG_CREATE_PROJECT_GENERATE = Messages.message("wts.dialog.createproject.generate");

    // setting
    public static final String SETTING_GIT_REPOSITORY = Messages.message("wts.setting.git.repository");
    public static final String SETTING_PROJECT_GROUPID = Messages.message("wts.setting.project.defaultGroupId");
    public static final String SETTING_PROJECT_ARTIFACTID = Messages.message("wts.setting.project.defaultArtifactId");
    public static final String SETTING_PROJECT_VERSION = Messages.message("wts.setting.project.defaultVersion");
    public static final String SETTING_PROJECT_PACKAGES = Messages.message("wts.setting.project.defaultPackages");
    public static final String SETTING_PROJECT_AUTHOR = Messages.message("wts.setting.project.defaultAuthor");

    @NotNull
    public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE_MESSAGE) String key, Object... params) {
        return CommonBundle.message(RESOURCE_BUNDLE, key, params);
    }
	
	private Messages() {
    }

    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }

    public static String getString(String key, Object...parms) {
        try {
            return MessageFormat.format(RESOURCE_BUNDLE.getString(key), parms);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
}
